import StoreModeBase from './StoreModeBase';
import callAPI from '@/common/helpers/callAPI';

const types = {
  GET_BASE_INFO: 'GET_BASE_INFO',
};

const initialState = {
  schoolData: {},
};

class SchoolMode extends StoreModeBase {
  reducer = (state = initialState, action) => {
    if(action.type === 'action maybe dispatched from other mode')
    {
      return {
        ...state,
        ...action.data,
      }
    }
    if (action.mode && action.mode === this.modeName) {
      return {
        ...state,
        ...action.data,
      };
    } else {
      return state;
    }
  };

  getBaseInfo = async (uid) => {
    return await callAPI(types.GET_BASE_INFO, { uid }).then((result) => {
      this.setState({ schoolData: result.data });
      return result;
    });
  };
}

const schoolMode = new SchoolMode('schoolMode');
export default schoolMode;
